﻿using System;
using System.Collections.Generic;
//using Allegro.TaskExecution.Core;

namespace Allegro.TaskExecution
{
    /// <summary>
    /// 
    /// </summary>
    public interface ITaskActivity
    {
        
    }
    /// <summary>
    /// Interfaace to be implemented by application specific activities
    /// </summary>
    public interface IAtomicTaskActivity : ITaskActivity
    {
        /// <summary>
        /// True if the task can be executed in the specified context
        /// </summary>
        bool CanExecute(IExecutionContext context);

        /// <summary>
        /// Execute the task. Before the task can be executed, a context must be registered for the task
        /// </summary>
        void Execute(ITask spawningTask, IExecutionContext context);
    }

    /// <summary>
    /// Interface to be implemented by composite activities
    /// </summary>
    public interface ICompositeTaskActivity : ITaskActivity
    {
        /// <summary>
        /// Invoked by the spawning task before any of the child activities have been executed
        /// </summary>
        /// <param name="spawningTask"></param>
        /// <param name="context"></param>
        void BeforeExecute(ITask spawningTask, IExecutionContext context);

        /// <summary>
        /// Invoked by the spawning task after all of the child activities have been executed
        /// </summary>
        /// <param name="spawningTask"></param>
        /// <param name="context"></param>
        void AfterExecute(ITask spawningTask, IExecutionContext context);

        /// <summary>
        /// If this task activity is composed of child activities, this method will
        /// be called by the spawning task once per child activity before the child activity
        /// executes. Use this method to initialize the child activity context, if necessary
        /// </summary>
        /// <param name="spawningTask"></param>
        /// <param name="childTask">Child activity</param>
        /// <param name="currentActivityContext">Context of this activity</param>
        /// <param name="childActivityContext">Context of the child activity</param>
        void PreProcessChildTask(ITask spawningTask, ITask childTask, IExecutionContext currentActivityContext, IExecutionContext childActivityContext);

        /// <summary>
        /// If this task activity is composed of child activities, this method will
        /// be called by the spawning task once per child activity after the child activity
        /// has completed. Use this method to integrate results from the child activity context into the current ativity
        /// context
        /// </summary>
        /// <param name="spawningTask"></param>
        /// <param name="childTask">Child activity</param>
        /// <param name="currentActivityContext">Context of this activity</param>
        /// <param name="childActivityContext">Context of the child activity</param>
        void PostProcessChildTask(ITask spawningTask, ITask childTask, IExecutionContext currentActivityContext, IExecutionContext childActivityContext);
    }
}
